<?php session_start(); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
<script type="text/javascript" src="../js/form.js"></script>
<script type="text/javascript" src="../js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
	theme : "advanced",
	mode : "textareas",
	language : "fr",
	plugins : "safari,insertdatetime",
	theme_advanced_buttons1 : "bold,italic,underline,hr,forecolor,outdent,indent,justifyleft,justifycenter,justifyright,justifyfull",
	theme_advanced_buttons2 : "image,insertdate,inserttime,bullist,fontselect,fontsizeselect",
	theme_advanced_buttons3 : "",
	width : "485", height : "450",
	theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "center"
});
</script>
</head>
</html>

<?php

include("../classes/ConnectionBDD.php");
include("../classes/FormulairesI.php");
include_once("../classes/portail.php");

$bdd = new Connector_Sql();
$frmI = new FormulairesI();
$p = new Portail();

mysql_connect('localhost','root','') or die('Connexion impossible a la BDD');
mysql_select_db('ABC PRO');

$mail = $_GET['mail'];

$id="";
$client="";

if($mail) {
	$fichier="../desc_e.tmp";
	$_SESSION['contenu']='vide';
}

else {
	if ($_SESSION['contenu'] == 'vide') $fichier="../desc_c.tmp";
	else {
		$fichier="../desc_m.tmp";
		$id = $_SESSION['contenu'];
		$client = $_SESSION['client'];
	}
}

$contenu = $p->lireFichier($fichier);

echo "<form name='desc_form' method='post' onsubmit='return verif(\"desc_form\");'>";

$frmI->zoneTexte('desc_d',$_SESSION['contenu'],$contenu); //cree une zone de texte avec un contenu ou non

echo "<center><button type='submit' name='valid'>Valider</button></center></form>";

if(isset($_POST['desc_d'])) {
	//creer le fichier desc.tmp contenant la description
	$f=fopen($fichier,"w") or die('Ouverture impossible');
	fwrite($f,$_POST['desc_d']."\r\n");
	fclose($f);
	$_SESSION['id']=$id;
	$_SESSION['cli']=$client;
}

$bdd->deconnect();

?>
